﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using SqlCon;


namespace yfxt
{
    public partial class cx_yfkc : Form
    {


        public string s_temp;
        public string S_temp
        {
            get { return s_temp; }
            set { this.s_temp = value; }
        }

        public cx_yfkc()
        {
            InitializeComponent();
        }



        SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction);
        private void button1_Click(object sender, EventArgs e)
        {
            string s = "select  yk_typk.pydm as pydm,ypmc,ypgg,ypdw,cdmc,yf_kcmx.lsjg as lsjg,yf_kcmx.ypsl as kcsl, " +
                       " (yf_kcmx.lsjg*yf_kcmx.ypsl)as kcje,yk_typk.ypxh as ypxh  " +
                       " from yk_typk,yf_kcmx,yk_ypcd,yk_cddz where yk_typk.ypxh=yf_kcmx.ypxh " +
                       " and yk_ypcd.ypxh=yk_typk.ypxh and yk_ypcd.ypcd=yk_cddz.ypcd" +
                //" and yk_typk.pydm like '" + textBox1.Text.ToString()+"%'"+
                       " group by  yk_typk.pydm,ypmc,ypgg,ypdw,cdmc,yf_kcmx.lsjg,yf_kcmx.ypsl,yk_typk.ypxh";


            if (conn.State != ConnectionState.Open) { conn.Open(); }

            using (SqlDataAdapter da = new SqlDataAdapter(s, conn))
            {
                DataTable dt = new DataTable();

                da.Fill(dt);

                dataGridView1.DataSource = dt;

            }


            dataGridView1.Columns[0].HeaderCell.Value = "拼音编码";
            dataGridView1.Columns[1].HeaderCell.Value = "药品名称";
            dataGridView1.Columns[2].HeaderCell.Value = "药品规格";
            dataGridView1.Columns[3].HeaderCell.Value = "药品单位";
            dataGridView1.Columns[4].HeaderCell.Value = "药品产地";
            dataGridView1.Columns[5].HeaderCell.Value = "零售价格";
            dataGridView1.Columns[6].HeaderCell.Value = "库存数量";
            dataGridView1.Columns[7].HeaderCell.Value = "库存金额";
            dataGridView1.Columns[8].HeaderCell.Value = "药库编码";
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            string s = "select  yk_typk.pydm as pydm,ypmc,ypgg,ypdw,cdmc,yf_kcmx.lsjg as lsjg,yf_kcmx.ypsl as kcsl, " +
                       " (yf_kcmx.lsjg*yf_kcmx.ypsl)as kcje,yk_typk.ypxh as ypxh  " +
                       " from yk_typk,yf_kcmx,yk_ypcd,yk_cddz where yk_typk.ypxh=yf_kcmx.ypxh " +
                       " and yk_ypcd.ypxh=yk_typk.ypxh and yk_ypcd.ypcd=yk_cddz.ypcd" +
                       " and yk_typk.pydm like '" + textBox1.Text.ToString() + "%'" +
                       " group by  yk_typk.pydm,ypmc,ypgg,ypdw,cdmc,yf_kcmx.lsjg,yf_kcmx.ypsl,yk_typk.ypxh";


            if (conn.State != ConnectionState.Open) { conn.Open(); }

            using (SqlDataAdapter da = new SqlDataAdapter(s, conn))
            {
                DataTable dt = new DataTable();

                da.Fill(dt);

                dataGridView1.DataSource = dt;

            }


            dataGridView1.Columns[0].HeaderCell.Value = "拼音编码";
            dataGridView1.Columns[1].HeaderCell.Value = "药品名称";
            dataGridView1.Columns[2].HeaderCell.Value = "药品规格";
            dataGridView1.Columns[3].HeaderCell.Value = "药品单位";
            dataGridView1.Columns[4].HeaderCell.Value = "药品产地";
            dataGridView1.Columns[5].HeaderCell.Value = "零售价格";
            dataGridView1.Columns[6].HeaderCell.Value = "库存数量";
            dataGridView1.Columns[7].HeaderCell.Value = "库存金额";
            dataGridView1.Columns[8].HeaderCell.Value = "药库编码";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cx_yfkc_Load(object sender, EventArgs e)
        {
            string s = "select  yk_typk.pydm as pydm,ypmc,ypgg,ypdw,cdmc,yf_kcmx.lsjg as lsjg,yf_kcmx.ypsl as kcsl, " +
                       " (yf_kcmx.lsjg*yf_kcmx.ypsl)as kcje,yk_typk.ypxh as ypxh  " +
                       " from yk_typk,yf_kcmx,yk_ypcd,yk_cddz where yk_typk.ypxh=yf_kcmx.ypxh " +
                       " and yk_ypcd.ypxh=yk_typk.ypxh and yk_ypcd.ypcd=yk_cddz.ypcd" +
                //" and yk_typk.pydm like '" + textBox1.Text.ToString()+"%'"+
                       " group by  yk_typk.pydm,ypmc,ypgg,ypdw,cdmc,yf_kcmx.lsjg,yf_kcmx.ypsl,yk_typk.ypxh";


            if (conn.State != ConnectionState.Open) { conn.Open(); }

            using (SqlDataAdapter da = new SqlDataAdapter(s, conn))
            {
                DataTable dt = new DataTable();

                da.Fill(dt);

                dataGridView1.DataSource = dt;

            }


            dataGridView1.Columns[0].HeaderCell.Value = "拼音编码";
            dataGridView1.Columns[1].HeaderCell.Value = "药品名称";
            dataGridView1.Columns[2].HeaderCell.Value = "药品规格";
            dataGridView1.Columns[3].HeaderCell.Value = "药品单位";
            dataGridView1.Columns[4].HeaderCell.Value = "药品产地";
            dataGridView1.Columns[5].HeaderCell.Value = "零售价格";
            dataGridView1.Columns[6].HeaderCell.Value = "库存数量";
            dataGridView1.Columns[7].HeaderCell.Value = "库存金额";
            dataGridView1.Columns[8].HeaderCell.Value = "药库编码";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            s_temp = textBox1.Text.ToString();

            cx_yfkc_dy dy = new cx_yfkc_dy();

            dy.Owner = this;

            dy.Show();


        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

            SqlHelper.s = dataGridView1.CurrentRow.Cells["ypxh"].Value.ToString();

            cx_ypxxcx_xg xg = new cx_ypxxcx_xg();

            xg.Owner = this;

            xg.Show();
        }
    }
}
